var app = new Vue({
    el: '#app',
    data: {
        lightList: [],
        admList: "",
        exhiList: [],
        firstSwiper: [],
        secondSwiper: [],
        objectId: "",
        lookmore: 0,
        Type: 0,
        timeType: 0,
        userId: 0,
        pageIndex: 1,
        pageSize: 10,
    },
    created() {
        FastClick.attach(document.body);
        $(document.body).infinite();
        if ($.getPara("userId") != "") {
            var userId = $.getPara("userId");
            this.userId = userId;
            $.setStorage("userId", userId)
        } else {
            if ($.getStorage("userId") && $.getStorage("userId") != "") {
                var userId = parseInt($.getStorage("userId"));
                this.userId = userId
            }
        }
        this.getLightShadowList(1, 0, this.pageIndex, this.pageSize);
        this.getExhiList(3, 0, this.pageIndex, this.pageSize);
        this.getFirstSwiper();
        this.getSecondSwiper();
        this.getFixedAdm()
    },
    mounted() {
        var that = this;
        $(".collTitle li").bind("click", function() {
            $(this).addClass("active").siblings().removeClass('active');
            var _index = $(this).index();
            var num = _index + 3;
            var _pageIndex = 1;
            that.exhiList = [];
            that.getExhiList(num, 0, _pageIndex, that.pageSize)
        })
    },
    methods: {
        backTop() {
            window.history.go(-1)
        },
        getLightShadowList(types, timeType, pageIndex, pageSize) {
            var that = this;
            var id = id;
            $.ajax({
                type: "GET",
                url: "/api/exhibition/list",
                dataType: 'json',
                data: {
                    type: types,
                    timeType: timeType,
                    pageIndex: pageIndex,
                    pageSize: pageSize
                },
            }).done(function(data, status, xhr) {
                if (data.code == 200) {
                    var list = data.data.list;
                    if (list.length > 0) {
                        var original = that.lightList;
                        var array = original.concat(list);
                        that.lightList = array
                    }
                } else {
                    $.toast("异常", "txt")
                }
            })
        },
        getExhiList(types, timeType, pageIndex, pageSize) {
            var that = this;
            that.lookmore = types - 1;
            $.ajax({
                type: "GET",
                url: "/api/exhibition/list",
                dataType: 'json',
                data: {
                    type: types,
                    timeType: timeType,
                    pageIndex: pageIndex,
                    pageSize: pageSize
                },
            }).done(function(data, status, xhr) {
                if (data.code == 200) {
                    var list = data.data.list;
                    if (list.length > 0) {
                        var original = that.exhiList;
                        var array = original.concat(list);
                        that.exhiList = array
                    }
                } else {
                    $.toast("异常", "txt")
                }
            })
        },
        getFirstSwiper() {
            var that = this;
            $.ajax({
                type: "GET",
                url: "/api/banner-ad/banner/index",
                dataType: 'json',
                data: {
                    type: 9,
                },
            }).done(function(data, status, xhr) {
                if (data.code == 200) {
                    var list = data.data;
                    if (list.length > 0) {
                        $.each(list, function(index, val) {
                            if (val.url_type == 0) {
                                that.firstSwiper += '<div class="swiper-slide"><a href="javascript:void(0)"><img src="' + val.img + '" /></a></div>'
                            } else {
                                that.firstSwiper += '<div class="swiper-slide"><a href="javascript:void(0)" onclick="urlHref_banner(' + val.url_value + ')"><img src="' + val.img + '" /></a></div>'
                            }
                        });
                        $("#exhi-firstwrapper").html(that.firstSwiper)
                    }
                    that.$nextTick(function() {
                        var swiper = new Swiper('#exhi-firstbanner',{
                            autoplay: 3000,
                            loop: true,
                            pagination: '.firstbanner-pagination',
                            autoplayDisableOnInteraction: false,
                        })
                    })
                } else {
                    $.toast("异常", "txt")
                }
            })
        },
        // 展会专访轮播图
        getSecondSwiper(types) {
            var that = this;
            $.ajax({
                type: "GET",
                url: "/api/banner-ad/banner/index",
                dataType: 'json',
                data: {
                    type: 12,
                },
            }).done(function(data, status, xhr) {
                if (data.code == 200) {
                    var list = data.data;
                    if (list.length > 0) {
                        $.each(list, function(index, val) {
                            if (val.url_type == 0) {
                                that.secondSwiper += '<div class="swiper-slide"><a href="javascript:void(0)"><img src="' + val.img + '" /></a></div>'
                            } else {
                                that.secondSwiper += '<div class="swiper-slide"><a href="javascript:void(0)" onclick="urlHref_banner(' + val.url_value + ')"><img src="' + val.img + '" /></a></div>'
                            }
                        });
                        $("#exhi-secwrapper").html(that.secondSwiper)
                    }
                    that.$nextTick(function() {
                        var swiper = new Swiper('#exhi-secbanner',{
                            autoplay: 3000,
                            loop: true,
                            pagination: '.secbanner-pagination',
                            autoplayDisableOnInteraction: false,
                        })
                    })
                } else {
                    $.toast("异常", "txt")
                }
            })
        },
        getFixedAdm() {
            var that = this;
            $.ajax({
                type: "GET",
                url: "/api/banner-ad/ad/byPositionType",
                dataType: 'json',
                data: {
                    positionType: 15,
                },
            }).done(function(data, status, xhr) {
                if (data.code == 200) {
                    var list = data.data;
                    if (list.length > 0) {
                        var original = that.admList;
                        var array = original.concat(list);
                        that.admList = array
                    }
                } else {
                    $.toast("异常", "txt")
                }
            })
        },
        urlHref(item) {
            var para = {};
            para.title = "展会列表";
            para.type = "exhibitionTabs";
            para.url = '/PageClassify/html/Exhibition/exhibitionTabs.html?type=' + item;
            if (this.userId > 0) {
                para.url = '/PageClassify/html/Exhibition/exhibitionTabs.html?type=' + item + "&userId=" + this.userId
            }
            if (/(Android)/i.test(navigator.userAgent)) {
                jsAndroid.appPush(JSON.stringify(para))
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                window.webkit.messageHandlers.appPush.postMessage(para)
            } else {
                window.location.href = para.url;
                alert("PC浏览器")
            }
        },
        urlHref_Details(item) {
            var para = {};
            para.title = "展会详情";
            para.type = "exhibitionDetails";
            para.url = '/PageClassify/html/Exhibition/exhibitionDetails.html?id=' + item.id;
            if (this.userId > 0) {
                para.url = '/PageClassify/html/Exhibition/exhibitionDetails.html?id=' + item.id + "&userId=" + this.userId
            }
            if (/(Android)/i.test(navigator.userAgent)) {
                jsAndroid.appPush(JSON.stringify(para))
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                window.webkit.messageHandlers.appPush.postMessage(para)
            } else {
                window.location.href = para.url;
                alert("PC浏览器")
            }
        },
    },
})
